{% extends 'layout.html' %}

{% block title %}商品详情{% endblock %}

{% block content %}
<<<<<<< HEAD
<div class="product-detail">
    <div class="product-images">
        <img src="{{ goods_data.goods_img.url }}" alt="{{ goods_data.goods_name }}" class="main-image">
    </div>
    
    <div class="product-info">
        <h1>{{ goods_data.goods_name }}</h1>
        <div class="price">¥{{ goods_data.goods_price }}</div>
        
        <div class="description">
            <p>{{ goods_data.goods_desc }}</p>
        </div>
        
        <div class="add-to-cart">
            <form id="add-to-cart-form">
                <input type="hidden" name="id" value="{{ goods_data.id }}">
                <input type="number" name="quantity" value="1" min="1" max="{{ goods_data.goods_quantity }}">
                <button type="submit">加入购物车</button>
            </form>
=======
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h1>{{ product.name }}</h1>
            <div class="product-image">
                <img src="{{ product.image_url }}" alt="{{ product.name }}" class="img-fluid">
            </div>
            <div class="product-details">
                <p><strong>价格:</strong> ¥{{ product.price }}</p>
                <p><strong>库存数量:</strong> {{ product.stock }}</p>
                <p><strong>最低库存:</strong> {{ product.min_stock }}</p>
                <p><strong>规格:</strong> {{ product.specification }}</p>
                <p><strong>计量单位:</strong> {{ product.unit }}</p>
                {% if product.shelf_life_end_date %}
                <p><strong>保质期截止日期:</strong> {{ product.shelf_life_end_date }}</p>
                {% endif %}
                <p><strong>描述:</strong></p>
                <p>{{ product.description }}</p>
            </div>
            <div class="product-quantity">
                <label for="quantity">数量:</label>
                <input type="number" id="quantity" name="quantity" value="1" min="1" max="{{ product.stock }}">
            </div>
            <div class="product-actions">
                <form action="/cart/add/" method="post">
                    {% csrf_token %}
                    <input type="hidden" name="product_id" value="{{ product.id }}">
                    <input type="hidden" name="quantity" id="quantity-input" value="1">
                    <button type="submit" class="btn btn-primary">加入购物车</button>
                </form>
            </div>
>>>>>>> 0ac75087e5e07a3ef0624f7a4a9866c7346941b7
        </div>
    </div>
</div>

<script>
<<<<<<< HEAD
$(document).ready(function() {
    $('#add-to-cart-form').submit(function(e) {
        e.preventDefault();
        $.ajax({
            url: '{% url 'add_cart' %}',
            type: 'GET',
            data: $(this).serialize(),
            success: function(response) {
                alert(response.status ? response.msg : response.errmsg);
            },
            error: function() {
                alert('添加购物车失败');
            }
        });
=======
    document.getElementById('quantity').addEventListener('change', function() {
        document.getElementById('quantity-input').value = this.value;
>>>>>>> 0ac75087e5e07a3ef0624f7a4a9866c7346941b7
    });
</script>

{% endblock %}